﻿#include <stdio.h>
#include <stdlib.h>
#include "AgUtUnicode.h"
#include "AgConnect.h"
#include <string.h>
#include <fstream>
#include <iostream>
#include <windows.h>
#include <string.h>
#include <atlstr.h>
extern "C" {

	char *AgEAppName  = "ConnectExample";
}
using namespace std;


int main()
{
	char        *connection1      = NULL;
	char        *initFileName     = NULL;
	static char  connectName[256] = "localHost:5001";
	char comand[2024];

	AgTConReturnInfo returnInfo;

	/* Initialize Connect */

	AgConInit(initFileName);


	/* Open a connection to STK */

	AgConOpenSTK(&connection1, 0, connectName);

	char buffer[256];


    cout<<"E:\share\erw.txt"<<"--- all file is as follows:---"<<endl;
	int number=0;
		while(0){//注意此处需要修改，如果正式运行记得把0改成1
	fstream outFile;
	outFile.open("E:\\share\\erw.txt",ios::in);
    outFile.getline(buffer,256,'\n');//getline(char *,int,char) 表示该行字符达到256个或遇到换行就结束
    string str=buffer;
	//std::cout<<str<<endl;
	SYSTEMTIME s_time;
	GetLocalTime(&s_time);
	//SetPosition */Satellite/Satellate2  ECI "8 May 2019 05:01:03.00 " -3793531.966071 4830147.160616 2622555.939970 -6373.450845 -3837.307982 -2083.485164
	sprintf(comand,"SetPosition */Satellite/Satellate2  ECI \"%d May 2019 %.2d:%.2d:%.2d.00 \" ", s_time.wDay, s_time.wHour,s_time.wMinute,s_time.wSecond);
	string command=comand;
	strcat(comand,buffer);
	cout<<"comand:"<<comand<<endl;
	number+=1;
	//if(number==2)
	{
		Sleep(1000);
		number=0;
	}
	outFile.close();
	AgConProcessSTKCmd(connection1, (char *)(LPCTSTR)comand, &returnInfo);
	AgConCleanupReturnInfo ( &returnInfo );
}


	char sendStr[]="New / Scenario Test";
    AgConProcessSTKCmd(connection1, (char *)(LPCTSTR)sendStr, &returnInfo);
	AgConCleanupReturnInfo ( &returnInfo );
	char sendStr1[]="NEW / */Satellite Satellate2"; AgConProcessSTKCmd(connection1, (char *)(LPCTSTR)sendStr, &returnInfo);
	AgConProcessSTKCmd(connection1, (char *)(LPCTSTR)sendStr1, &returnInfo);
	AgConCleanupReturnInfo ( &returnInfo );
/*	char sendStr2[]="Animate * Start";
	AgConProcessSTKCmd(connection1, (char *)(LPCTSTR)sendStr2, &returnInfo);AgConCleanupReturnInfo ( &returnInfo );
	/* Set verbose and ack on */
	char sendStr3[]="Position */Satellite/Satellate3";
	AgConProcessSTKCmd(connection1, (char *)(LPCTSTR)sendStr3, &returnInfo);
	//sprintf("???===>%s",returnInfo.returnList[0]);
	cout<<returnInfo.returnList[0][223]<<endl;
	cout<<typeid(returnInfo.returnList[0]).name()<<endl;




	//cout<<sizeof(&returnInfo.returnList[0])<<endl;
	string str1(returnInfo.returnList[0]);
	cout<<str1<<endl;
	cout<<str1.length()<<endl;
	vector< vector<int>> result;
	char positionset[]="SetPosition */Satellite/Satellate3  ECI \"10 May 2019 05:01:03.00 ";
	//查询得知，returnInfo是一个数组，其中包含了所有需要的消息，尝试把消息读取出来，已经成功。returnInfo【0】
	int q=0;
	char temp[256]="";
	for (int i=0;i<str1.length();i++)
	{

		if(returnInfo.returnList[0][i]==' ')

		{	cout<<i<<endl;
			if(q>=12&&q<=17)

			{
				for(int i_2=i+1; ; i+2++)
				{
					if()
				}
			}
			//cout<<returnInfo.returnList[0][i];
				//temp[q]=returnInfo.returnList[0][i];
		q++;}

	}
	cout<<q<<endl;

	/*for (int s=0;s<sizeof(temp);s++)
				{if(temp[s]!=NULL)
				cout<<temp[s];}*/

	AgConCleanupReturnInfo ( &returnInfo );









	AgConCloseSTK(&connection1);


	/*  Wait for user to respond */
	system("pause");

	/*  Clean up the Return Information, freeing any unneeded memory */
	AgConCleanupReturnInfo ( &returnInfo );

	/*  Free remaining allocated memory in the Connect module in
	*  preparation for exit
	*/
	AgConShutdownConnect();

	return (0);
}
